package com.rightsidetech.http.controller.agentAdmin.activity;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.activity.dto.request.ride.ActRidePageReq;
import com.rightsidetech.activity.dto.response.RideActivityResp;
import com.rightsidetech.activity.service.ActRideService;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.service.SysAgentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Package: com.rightsidetech.http.controller.agentAdmin.activity
 * @ClassName: AgentActRideController
 * @Author: yinj
 * @CreateTime: 2022/03/02 10:39
 */
@RestController
@RequestMapping("/agentAdmin/ride_act/")
@ShenyuSpringMvcClient(path = "/agentAdmin/ride_act/**")
@Api(tags = "代理商-骑行活动相关")
public class AgentActRideController extends BaseController {

    @Resource
    private ActRideService actRideService;
    @Resource
    private SysAgentInfoService sysAgentInfoService;

    @Token
    @Log
    @GetMapping("/page")
    @ApiOperation("分页查询骑行活动")
    @Auth(bizType = Auth.AGENT)
    public ResponseData<PageInfo<RideActivityResp>> ridePage(ActRidePageReq req){
        Long loginInfoId = Long.parseLong(getAttribute());
        //获取登录账号代理商id
        Long agentInfoId = sysAgentInfoService.findAgentInfoId(loginInfoId);
        if (StringUtils.isEmpty(agentInfoId)){
            return ResponseData.fail(CodeIdEnum.Expired);
        }
        req.setAgentInfoId(agentInfoId);
        return actRideService.page(req);
    }

}
